<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>Layui</title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
		<link rel="stylesheet" href="../layui/css/layui.css" media="all">
		<!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
	</head>
	<body>
		<fieldset class="layui-elem-field layui-field-title" style="margin-top: 50px;">
			<legend>添加汽车</legend>
		</fieldset>

		<form class="layui-form" action="" lay-filter="example">
			<div class="layui-form-item">
				<label class="layui-form-label">汽车名称</label>
				<div class="layui-input-block">
					<input type="text" name="carName" lay-verify="title" autocomplete="off" placeholder="请输入汽车名称"
						class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">每日租金</label>
				<div class="layui-input-block">
					<input type="text" name="dailyPrice" lay-verify="title" placeholder="请输入每日租金" autocomplete="off"
						class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">图片链接</label>
				<div class="layui-input-block">
					<input type="text" name="imageUrl" lay-verify="title" autocomplete="off" placeholder="请输入图片链接"
						class="layui-input">
				</div>
				
			</div>
			<div class="layui-form-item">
		    <label class="layui-form-label">汽车品牌</label>
		    <div class="layui-input-block">
		      <input type="text" name="brand" lay-verify="title" autocomplete="off" placeholder="请输入汽车品牌" class="layui-input">
		    </div>
		  </div>
			<div class="layui-form-item">
				<label class="layui-form-label">出厂年份</label>
				<div class="layui-input-block">
				  <input type="text" name="productYear" class="layui-input" id="test2">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">出厂国家</label>
				<div class="layui-input-block">
				  <input type="text" name="productCountry" class="layui-input" placeholder="请输入出厂国家">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">车身颜色</label>
				<div class="layui-input-block">
				  <input type="text" name="color" class="layui-input" placeholder="请输入车身颜色" >
				</div>
			</div>



			<div class="layui-form-item">
				<div class="layui-input-block">
					<button type="reset" class="layui-btn layui-btn-primary">重置</button>
					<button type="submit" class="layui-btn" lay-submit="" lay-filter="demo1">添加汽车</button>
					<!-- <button type="button" id="LAY-component-form-getval">验证</button> -->
				</div>
			</div>
		</form>

		<script src="../layui/layui.js" charset="utf-8"></script>
		<!-- <script type="text/javascript" src="layui/js/jquery-1.8.3.min.js"></script> -->
		<!-- 注意：如果你直接复制所有代码到本地，上述 JS 路径需要改成你本地的 -->
		<script>
		
		layui.use('laydate', function(laydate){  
		  
		  //全局配置
		  laydate.set({
		    //trigger: 'focus'
		  })
		
		
		  //单控件
		  laydate.render({
		    elem: '#test2'
		    //,format: 'yyyy年MM月dd日'
		    ,value: new Date(1534766888000)
		    //,isInitValue: false
		    ,format: 'yyyy-MM-dd'
		    ,min: 7
		    //,max: 0
		    //,min: '2016-10-14'
		    //,max: -1
		    //,value: '1989年10月14日'
		    
		    ,done: function(productYear, date, endDate){
		      console.log(productYear);
		    }
		   
		  });
		  
		 
		});
		</script>
		<script>
			layui.use(['form', 'layedit', 'laydate'], function() {
				var form = layui.form,
					layer = layui.layer,
					$ = layui.jquery,
					layedit = layui.layedit,
					laydate = layui.laydate;

				//自定义验证规则
				form.verify({
					title: function(value) {
						if (value.length < 1) {
							return '此栏不能为空噢';
						}
					}

				});


				//监听提交
				form.on('submit(demo1)', function(data) {
					console.log(data);
					$.post({
						url: 'http://localhost:8085/admin/car/addCar',
						data: JSON.stringify(data.field),
						dataType: "json",
						timeout: 300000,
						contentType: 'application/json; charset=UTF-8',
						success: function(result) {
							if (result) {
								layer.msg("添加成功", {
									time: 1000
								}, function() {
									location.href = "course_list.html";
								});
							}
						}
					});
					return false;
				});



				//表单取值
				layui.$('#LAY-component-form-getval').on('click', function() {
					var data = form.val('example');
					// alert(JSON.stringify(data));
					console.log(data);
				});

			});
		</script>
		<style>
			.layui-input {
				width: 100%
			}
		</style>
	</body>
</html>
